// 导入Vue框架
import Vue from 'vue';
// 导入app.vue组件
import App from './app.vue';

import VueRouter from 'vue-router';
Vue.use(VueRouter);
const Routers = [
	{
		path: '/index',
		meta: {
			title: '首页',
		},
		component:(resolve) => require(['./router/views/index.vue'],resolve)
	},
	{
		path: '/about',
		meta: {
			title: '关于',
		},
		component:(resolve) => require(['./router/views/about.vue'],resolve)
	},
	{
		path: '/user/:id',
		meta: {
			title: '个人主页',
		},
		component:(resolve) => require(['./router/views/user.vue'],resolve)
	},
	{
		path: '*',
		redirect: '/index'
	}
];
const RouterConfig = {
	mode: 'history',
	routes: Routers
};
const router = new VueRouter(RouterConfig);
router.beforeEach((to,form,next) => {
	// 标题设置
	window.document.title = to.meta.title;
	next();
})
router.afterEach((to,form,next) => {
	// 返回页面顶部
	window.scrollTo(0,0);
})

// 创建Vue根实例
new Vue({
	el: '#app',
	/**
	 * =>是箭头函数
	 * render: h => h(App)等同于:
	 * render: function(h){
	 *	return h(App) 
	 * }
	 */
	render: h => h(App),
	router: router
})